package com.example.xungeng2.config;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

@Component
@Slf4j
public class MyMetaDataObjectHandler implements MetaObjectHandler {
    @Override
    public void insertFill(MetaObject metaObject) {
        log.info("插入数据时执行此语句");
        DateFormat format = new SimpleDateFormat("yyyy-MM-dd");
        String format1 = format.format(new Date());
        Date date = null;
        try {
            date = format.parse(format1);
        } catch (ParseException e) {
            throw new RuntimeException(e);
        }
        metaObject.setValue("date",date);
        log.info("插入数据后的信息{}",date);
    }

    @Override
    public void updateFill(MetaObject metaObject) {

    }
}
